import { createRouter, createWebHashHistory } from "vue-router";

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/login",
      name: "login",
      component: () => import("../pages/login/index.vue"),
    },
    {
      path: "/404",
      name: "404",
      component: () => import("../pages/nodata/index.vue"),
    },
    {
      path: "/:catchAll(.*)",
      name: "404",
      component: () => import("../pages/nodata/index.vue"),
    },
  ],
});

router.beforeEach((to, from, next) => {
  const info = localStorage.getItem("userinfo");
  if (info || to.path == "/login") {
    next();
  } else {
    next("/login");
  }
});

export default router;
